/*
-----------------------------------------------------------------------------
Filename:    TutorialApplication.cpp
-----------------------------------------------------------------------------

This source file is part of the
   ___                 __    __ _ _    _ 
  /___\__ _ _ __ ___  / / /\ \ (_) | _(_)
 //  // _` | '__/ _ \ \ \/  \/ / | |/ / |
/ \_// (_| | | |  __/  \  /\  /| |   <| |
\___/ \__, |_|  \___|   \/  \/ |_|_|\_\_|
      |___/                              
      Tutorial Framework
      http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#include "TutorialApplication.h"

//-------------------------------------------------------------------------------------
TutorialApplication::TutorialApplication(void)
{
}
//-------------------------------------------------------------------------------------
TutorialApplication::~TutorialApplication(void)
{
}

//-------------------------------------------------------------------------------------
void TutorialApplication::createScene(void)
{
	// Set the ambient light
	mSceneMgr->setAmbientLight(Ogre::ColourValue::White);

/*------
* Camera
* 
* TODO:
* Change the camera so that it isn't free-floating.
* Create a camera that is controllable in an FPS-style
* Also may need to have it's own collision so it can't bump into the Hiding Objects
-------*/
	mCamera->setPosition(300, 50, 300);
	mCamera->lookAt(0, 0, 0);

/*-------------------------
* Create the Plane Objects
--------------------------*/

	// Create Plane 1
	Ogre::Plane plane1;
	plane1.normal = Ogre::Vector3::UNIT_Y;	// If this is changed to UNIT_Z, change the MeshManager to UNIT_Y; Oject becomes vertical
	plane1.d = 0;							// This basically defines the height position of the plane in world space
	
	// Create Plane 2
	Ogre::Plane plane2;
	plane2.normal = Ogre::Vector3::UNIT_Y;
	plane2.d = 100;

	// Create Plane 3
	Ogre::Plane plane3;
	plane3.normal = Ogre::Vector3::UNIT_Y;
	plane3.d = 200;

	// Create Plane 4
	Ogre::Plane plane4;
	plane4.normal = Ogre::Vector3::UNIT_Y;
	plane4.d = 300;

/*----------
* Plane One
-----------*/
	// Using the MeshManager to create a plane
	Ogre::MeshManager::getSingleton().createPlane("floor1",				// The Plane's Mesh Name
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,		// Using the Default Group Name
		plane1,															// Specify which Plane Object to use
		450.0f, 450.0f, 10, 10, true,									// Plane dimensions are 450x450, Each segment is 10x10, Normals are set to TRUE
		1, 50.0f, 50.0f,												// Number of texture Coord Sets, U and V tile size
		Ogre::Vector3::UNIT_Z);											// Plane' upVector

	Ogre::Entity* planeEnt1 = mSceneMgr->createEntity("plane1", "floor1");	// Create an Entity for the plane and specify the Plane object and it's Mesh
	planeEnt1->setMaterialName("Examples/BumpyMetal");						// Set the material - Using the example material found in $(OGRE_HOME)\media\materials\scripts
	planeEnt1->setCastShadows(false);										// Don't let the plane cast shadows as I think it should only receive them instead
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt1);	// Attach

/*----------
* Plane Two
-----------*/
	Ogre::MeshManager::getSingleton().createPlane("floor2",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane2,
		450.0f, 450.0f, 10, 10, true, 1, 50.0f, 50.0f,
		Ogre::Vector3::UNIT_Z);

	Ogre::Entity* planeEnt2 = mSceneMgr->createEntity("plane2", "floor2");
	planeEnt2->setMaterialName("Examples/Rockwall");
	planeEnt2->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt2);

/*-----------
* Plane Three
------------*/
	Ogre::MeshManager::getSingleton().createPlane("floor3",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane3,
		450.0f, 450.0f, 10, 10, true, 1, 50.0f, 50.0f,
		Ogre::Vector3::UNIT_Z);

	Ogre::Entity* planeEnt3 = mSceneMgr->createEntity("plane3", "floor3");
	planeEnt3->setMaterialName("Examples/BeachStones");
	planeEnt3->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt3);

/*----------
* Plane Four
-----------*/
	Ogre::MeshManager::getSingleton().createPlane("floor4",
		Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane4,
		450.0f, 450.0f, 10, 10, true, 1, 50.0f, 50.0f,
		Ogre::Vector3::UNIT_Z);

	Ogre::Entity* planeEnt4 = mSceneMgr->createEntity("plane4", "floor4");
	planeEnt4->setMaterialName("Examples/GrassFloor");
	planeEnt4->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(planeEnt4);

}



#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        TutorialApplication app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif
